<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>辅导员信息页</title>
</head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">
<script src="/js/vue/vue.min.js"></script>
<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/laypage/laypage.js" charset="utf-8"></script>
<script src="/js/layer/layer.js" charset="utf-8"></script>
<body>
<style>
    .assistant {
        float: right;
    }
</style>
<div id="app" class="container">

    <span class="assistant">欢迎 ${Session.assistant.assistant_name} 访问</span>
    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="assistant_name">辅导员姓名</label>
            <input type="text" class="form-control" id="assistant_name" value="" placeholder="辅导员姓名">
        </div>
        <div class="form-group">
            <label class="sr-only" for="phone">辅导员手机号</label>
            <input type="text" class="form-control" id="phone" value="" placeholder="辅导员手机号">
        </div>
        <button type="button" id="findAssistant" class="btn btn-success">辅导员查询</button>
        <button type="button" id="addAssistantBtn" class="btn btn-danger">添加辅导员</button>
    </form>


    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>工号</td>
                <td>姓名</td>
                <td>手机号</td>
                <td>密码</td>
                <td>所属院系</td>
                <td>邮箱</td>
                <td>状态</td>
                <td>角色</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.assistant_name}}</td>
                <td>{{item.phone}}</td>
                <td>{{item.pwd}}</td>
                <td>{{item.dept.dept_name}}</td>
                <td>{{item.email}}</td>
                <td>{{item.assistant_state}}</td>
                <td>{{item.role.role_name}}</td>
                <td>
                    <a href="#" @click="editEvent(item.id)">编辑</a>
                    <a href="#" @click="delEvent(item.assistant_id)">删除</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getAssistantPageList = function (curr) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/assistant/getPage.do",
            data: {
                pageNum: curr || 1,
                pageSize: 5,
                assistant_name: $("#assistant_name").val(),
                phone: $("#phone").val()
            },
            success: function (msg) {
                app.result = msg.page;
                laypage({
                    skin: '#FFB6C1',
                    cont: 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                    pages: msg.totalPage, //总页数
                    first: "第一页",
                    last: "最后一页",
                    curr: curr || 1, //当前页
                    jump: function (obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                            getAssistantPageList(obj.curr);
                        }
                    }
                });
            }
        });
    };

    getAssistantPageList();

    $("#findAssistant").click(function () {
        getAssistantPageList();
    });

    $("#addAssistantBtn").click(function () {
        layer.open({
            type: 2,
            title: '添加用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['900px', '600px'],
            content: '/assistant/toAddAssistant.do',
            dataType: "json",
            end: function (data) {
                getAssistantPageList();
            }
        });
    });

    //编辑用户
    var editEvent = function (assistant_id) {
        layer.open({
            type: 2,
            title: '编辑用户',
            fixed: false,
            maxmin: true,
            shadeClose: true,
            area: ['900px', '600px'],
            content: '/assistant/toUpdateAssistant.do?id=' + assistant_id,
            end: function () {
                getAssistantPageList();
            }
        });
    };

    //删除用户
    var delEvent = function (assistant_id) {
        //删除确认
        layer.confirm("确定要删除吗？", {
                    bth: ['是', '否']
                }, function () {    //如果点击了第一个按钮 ——是
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        url: "/assistant/deleteAssistant.do",
                        data: {
                            "assistant_id": assistant_id
                        },
                        success:function (uu) {
                            getAssistantPageList();
                            layer.msg("已经删除了id为" + assistant_id + "的记录", {icon: 5});
                        }
                    });
                }
        );
    }

</script>
</body>
</html>